package com.example.hanfu_bk.service;

import com.example.hanfu_bk.mapper.HanfuMapper;
import com.example.hanfu_bk.pojo.Hanfu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HanfuService {

    @Autowired
    private HanfuMapper hanfuMapper;

    // 保存完整的汉服定制信息
    public int saveHanfu(Hanfu hanfu) {
        return hanfuMapper.insertHanfu(hanfu);
    }
    //查询用户的定制记录
    public List<Hanfu> getRecordsByUserId(Integer userId) {
        return hanfuMapper.selectByUserId(userId);
    }
    public boolean deleteByUserIdAndRecordId(Integer userId, Integer recordId) {
        // 1. 先查询记录是否存在，且属于当前用户
        Hanfu hanfu = hanfuMapper.selectByUserIdAndRecordId(userId, recordId);
        if (hanfu == null) {
            // 记录不存在或不属于当前用户
            return false;
        }
        // 2. 执行删除
        int rows = hanfuMapper.deleteByUserIdAndRecordId(userId, recordId);
        return rows > 0;
    }
}